package com.webchat.admin.service.mall;

import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.mall.SaveMallCategoryRequestVO;
import com.webchat.rmi.pgc.mall.MallCategoryClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MallCategoryService {

    @Autowired
    private MallCategoryClient mallCategoryClient;

    /**
     * 创建、更新商品分类
     *
     * @param requestVO
     * @return
     */
    public Long saveCategory(SaveMallCategoryRequestVO requestVO) {

        APIResponseBean<Long> apiResponseBean = mallCategoryClient.save(requestVO);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return apiResponseBean.getData();
        }
        return null;
    }

    /**
     * 发布分类
     *
     * @param id
     * @param userId
     * @return
     */
    public boolean publish(Long id, String userId) {

        APIResponseBean<Boolean> apiResponseBean = mallCategoryClient.publish(id, userId);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return apiResponseBean.getData();
        }
        return false;
    }

    /**
     * 撤回分类
     *
     * @param id
     * @param userId
     * @return
     */
    public boolean invoke(Long id, String userId) {

        APIResponseBean<Boolean> apiResponseBean = mallCategoryClient.invoke(id, userId);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return apiResponseBean.getData();
        }
        return false;
    }

    /**
     * 删除分类
     *
     * @param id
     * @param userId
     * @return
     */
    public boolean delete(Long id, String userId) {

        APIResponseBean<Boolean> apiResponseBean = mallCategoryClient.delete(id, userId);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return apiResponseBean.getData();
        }
        return false;
    }


    /**
     * 修改分类优先级
     *
     * @param id
     * @param rank
     * @param userId
     * @return
     */
    public boolean updateRank(Long id, Integer rank, String userId) {

        APIResponseBean<Boolean> apiResponseBean = mallCategoryClient.updateRank(id, rank, userId);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return apiResponseBean.getData();
        }
        return false;
    }

}
